module.exports = class extends think.kms.admin {
  async indexAction() {
    const info = await this.model('kms/system_config').getSystem_info();
    this.assign({
      title: '网站参数配置',
      system_name: info.site_name,
      system_copy: info.site_copy,
      system_app_name: info.app_name,
      system_version: info.app_version,
      tongji_baidu_key: info.tongji_baidu_key,
      browser_icon: info.browser_icon
    });
    return this.display();
  }

  async fileAction() {
    const info = await this.model('kms/system_config').getSystem_info();
    this.assign({
      alert: {
        title: '操作安全警告（默认使用本地服务存储）',
        content: '请根据实际情况配置存储引擎，合理做好站点下载分流。建议尽量使用云存储服务，同时保证文件访问协议与网站访问协议一致！',
        type: 'danger'
      },
      title: '文件存储配置',
      storage_type: info.storage_type,
      storage_local_exts: info.storage_local_exts,
      storage_qiniu_region: info.storage_qiniu_region,
      storage_qiniu_is_https: info.storage_qiniu_is_https,
      storage_qiniu_bucket: info.storage_qiniu_bucket,
      storage_qiniu_domain: info.storage_qiniu_domain,
      storage_qiniu_access_key: info.storage_qiniu_access_key,
      storage_qiniu_secret_key: info.storage_qiniu_secret_key,
      storage_oss_is_https: info.storage_oss_is_https,
      storage_oss_bucket: info.storage_oss_bucket,
      storage_oss_domain: info.storage_oss_domain,
      storage_oss_keyid: info.storage_oss_keyid,
      storage_oss_secret: info.storage_oss_secret,
    })
    return this.display();
  }
  
  async updateSystemInfoAction() {
    const data = await this.model('kms/system_config').update_system_info(this.post());
    if (data) {
      return this.success('修改成功！');
    } else {
      return this.fail('修改失败！');
    }
  }

  async getconfigAction() {
    const info = await this.model('kms/system_config').getSystem_info();
    return this.json({
      system_name: info.site_name,
      system_copy: info.site_copy,
      system_app_name: info.app_name,
      system_version: info.app_version,
      tongji_baidu_key: info.tongji_baidu_key,
      browser_icon: info.browser_icon
    })
  }

  async getFileInfoAction() {
    const info = await this.model('kms/system_config').getSystem_info();
    let data = Object.assign({
      alert: {
        title: '操作安全警告（默认使用本地服务存储）',
        content: '请根据实际情况配置存储引擎，合理做好站点下载分流。建议尽量使用云存储服务，同时保证文件访问协议与网站访问协议一致！',
        type: 'danger'
      },
      title: '文件存储配置',
      storage_type: info.storage_type,
      storage_local_exts: info.storage_local_exts,
      storage_qiniu_region: info.storage_qiniu_region,
      storage_qiniu_is_https: info.storage_qiniu_is_https,
      storage_qiniu_bucket: info.storage_qiniu_bucket,
      storage_qiniu_domain: info.storage_qiniu_domain,
      storage_qiniu_access_key: info.storage_qiniu_access_key,
      storage_qiniu_secret_key: info.storage_qiniu_secret_key,
      storage_oss_is_https: info.storage_oss_is_https,
      storage_oss_bucket: info.storage_oss_bucket,
      storage_oss_domain: info.storage_oss_domain,
      storage_oss_keyid: info.storage_oss_keyid,
      storage_oss_secret: info.storage_oss_secret,
    });
    return this.json(data);
  }
};
